home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 12 / CU Amiga Magazine's Super CD-ROM 12 (1997)(EMAP Images)(GB)[!][issue 1997-07].iso / CUCD / Programming / PopupMenu / Demos / Demo.c < prev    next >
C/C++ Source or Header  |  1997-03-23  |  3KB  |  133 lines

  1. //
  2. // $VER: Demo.c 1.1 (23.3.97)
  3. //
  4. // Popup Menu example program
  5. //
  6. // ©1996-1997 Henrik Isaksson
  7. // All Rights Reserved.
  8. //
  9. // Run and click the mouse in the window and over the dragbar!
  10. // (two different menus)
  11. //
  12.  
  13. #include <intuition/intuition.h>
  14.  
  15. #include <clib/intuition_protos.h>
  16. #include <clib/exec_protos.h>
  17. #include <clib/alib_protos.h>
  18.  
  19. #include <string.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22.  
  23. #include <libraries/pm.h>
  24. #include <proto/pm.h>
  25.  
  26. struct IntuitionBase    *IntuitionBase;
  27. struct GfxBase        *GfxBase;
  28. struct PopupMenuBase    *PopupMenuBase;
  29.  
  30. struct Window *w;    // This window is only needed to find out when and where the menu should appear.
  31.             // The font in this window's rastport will be used for the menu.
  32.  
  33. BOOL HandleReturnCodes(ULONG rc)
  34. {
  35.     BOOL running=TRUE;
  36.  
  37.     switch(rc) {
  38.         case 10:
  39.             system("RUN <>NIL: Disable");
  40.             break;
  41.         case 15:
  42.             system("RUN <>NIL: StartMenu");
  43.             break;
  44.         case 20:
  45.             system("RUN <>NIL: SimpleMenu");
  46.             break;
  47.         case 25:
  48.             system("RUN <>NIL: OldStyle");
  49.             break;
  50.         case 5:
  51.             running=FALSE;
  52.             break;
  53.     }
  54.  
  55.     return running;
  56. }
  57.  
  58. void main()
  59. {
  60.     BOOL r=TRUE;
  61.     struct IntuiMessage *im,imsg;
  62.     struct PopupMenu *p1,*p2;
  63.  
  64.     PopupMenuBase=(struct PopupMenuBase *)OpenLibrary(POPUPMENU_NAME,POPUPMENU_VERSION);            // Open the library
  65.     if(PopupMenuBase) {
  66.         IntuitionBase=(struct IntuitionBase *)PopupMenuBase->pmb_IntuitionBase;    // We let popupmenu.library open the libraries we need
  67.         GfxBase=(struct GfxBase *)PopupMenuBase->pmb_GfxBase;            // They remain valid until the library is closed!
  68.  
  69.         p1=PMMenu("Run Demos"),
  70.             PMItem("Disable"),    PM_UserData,    10,    End,
  71.             PMItem("StartMenu"),    PM_UserData,    15,    End,
  72.             PMItem("SimpleMenu"),    PM_UserData,    20,    End,
  73.             PMItem("OldStyle"),    PM_UserData,    25,    End,
  74.             End;
  75.  
  76.         p2=PMMenu("PopupMenu Demo"),
  77.             PMItem("About..."),                End,
  78.             PMTitleBar,                    End,
  79.             PMItem("Quit"),        PM_UserData,    5,    End,
  80.             End;
  81.  
  82.         if(p1 && p2) {
  83.             w=OpenWindowTags(NULL,    WA_IDCMP,    IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS,    // Open a little window
  84.                     WA_RMBTrap,    TRUE,
  85.                     WA_DragBar,    TRUE,
  86.                     WA_Left,    150,
  87.                     WA_Top,        100,
  88.                     WA_Width,    150,
  89.                     WA_Height,    100,
  90.                     WA_SizeGadget,    TRUE,
  91.                     WA_DepthGadget,    TRUE,
  92.                     WA_MinWidth,    150,
  93.                     WA_MaxWidth,    1280,
  94.                     WA_MinHeight,    100,
  95.                     WA_MaxHeight,    1024,
  96.                     WA_Title,    "Popup Menu Demo",
  97.                     WA_CloseGadget,    TRUE,
  98.                     TAG_DONE);
  99.             if(w) {
  100.  
  101.                 while(r) {
  102.                     WaitPort(w->UserPort);                        // Wait for a message
  103.                     while((im=(struct IntuiMessage *)GetMsg(w->UserPort))) {    // Get the message
  104.                         CopyMem(im,&imsg,sizeof(struct IntuiMessage));        // Copy the contents of it
  105.                         ReplyMsg((struct Message *)im);                // Reply the message
  106.  
  107.                         switch(imsg.Class) {
  108.                             case IDCMP_CLOSEWINDOW: r=FALSE; break;
  109.                             case IDCMP_MOUSEBUTTONS:            // The user has hit a mousebutton - time to open the menu!
  110.                                 if(w->MouseY>w->BorderTop) {
  111.                                     r=HandleReturnCodes(PM_OpenPopupMenu(w,
  112.                                         PM_Menu,        p1,
  113.                                         PM_Code,        imsg.Code,
  114.                                         TAG_DONE));
  115.                                 } else {
  116.                                     r=HandleReturnCodes(PM_OpenPopupMenu(w,
  117.                                         PM_Menu,        p2,
  118.                                         PM_Code,        imsg.Code,
  119.                                         TAG_DONE));
  120.                                 }
  121.                             break;
  122.                         }
  123.                     }
  124.                 }
  125.                 CloseWindow(w);
  126.             } else printf("Window error!\n");
  127.         } else printf("Menu error!\n");
  128.         if(p1) PM_FreePopupMenu(p1);
  129.         if(p2) PM_FreePopupMenu(p2);
  130.         CloseLibrary((struct Library *)PopupMenuBase);
  131.     }
  132. }
  133.